package sjtu.ist.warehouse4ws.action;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.json.annotations.JSON;

import com.opensymphony.xwork2.ActionSupport;

public class SessionAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = -6336991553174805971L;
	private String sessionId=null;
	private String userName=null;

	/**
	 * @param sessionId the sessionId to set
	 */
	public void setSessionId(String sessionId) {
		this.sessionId = sessionId;
	}
	
	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String showSessionId(){
		sessionId=ServletActionContext.getRequest().getSession().getId();
		System.out.println("SsessionAction:"+sessionId);
		
		Subject currentUser = SecurityUtils.getSubject();

		Object obj=currentUser.getSession().getAttribute("username");
		userName=obj.toString();
		
		return SUCCESS;
	}
	/**
	 * @return the sessionId
	 */
	@JSON(name = "sessionId")
	public String getSessionId() {
		return sessionId;
	}
	/**
	 * @return the companyId
	 */
	@JSON(name = "userName")
	public String getUserName() {
		return userName;
	}
}